package com.test.controller;

import com.alibaba.fastjson.JSONObject;
import com.test.pojo.AdminUser;
import com.test.service.AdminUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@Controller
public class AdminUserCtrl {
    @Resource
    AdminUserService adminUserService;
    //登陆验证-ajax
    @ResponseBody
    @RequestMapping(value = "/doLogin",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public String doLogin(AdminUser adminUser, HttpSession session, Model model) {
        // 进行登录判断
        AdminUser resUser = adminUserService.doLogin(adminUser.getAdminName(),adminUser.getAdminPassword());
        JSONObject object = new JSONObject();
        if (resUser != null) {
            session.setAttribute("adminUser",adminUser.getAdminName());
            object.put("success",true);
        }else{
            model.addAttribute("msg","请核对用户名或密码");
            object.put("success",false);
        }
        return object.toJSONString();
    }
}
